import React, { ReactElement } from 'react'
import ReactDOM from 'react-dom'
const PREFIX = 'gzwModal'
interface Props {
  text: string | ReactElement
  title?: string
  onCancel?: () => void
}
class Modal {
  getClassName(str: string = '') {
    return `${PREFIX}${str}`
  }
  comfireModal(params: Props) {
    const { text, onCancel, title } = params
    const div = document.createElement('div')
    const mask = <div className={this.getClassName('')}>
      <div className={this.getClassName('Form')}>
        {
          title &&
          <div className={this.getClassName('Title')}>
            { title}
          </div>
        }
        <div className={this.getClassName('Body')}>
          {text}
        </div>
        <div className={this.getClassName('Close')} onClick={() => {
          onCancel && onCancel()
          document.body.removeChild(div)
        }
        }>
          确定
        </div>
      </div>
    </div>
    ReactDOM.render(mask, div)
    document.body.append(div)
  }
}
const modal = new Modal()
export default modal
